package com.proxyhub.crawler;

import com.proxyhub.annotation.Crawler;
import com.proxyhub.repo.ProxyRepo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by linxsh on 2017/6/15.
 */
public abstract class BaseCrawler implements Runnable {
    private static final Logger logger = LoggerFactory.getLogger(BaseCrawler.class);

    @Autowired
    protected ProxyRepo proxyRepo;

    @Override
    public void run() {
        Crawler crawler = this.getClass().getAnnotation(Crawler.class);
        String crawlerName;
        if(crawler != null) {
            crawlerName = crawler.value();
        } else {
            crawlerName = this.getClass().getName();
        }
        logger.info("[{}]开始更新数据", crawlerName);
        crawl();
        logger.info("[{}]更新数据结束", crawlerName);
    }

    public abstract void crawl();
}
